package com.scf.fruit.enums;

import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * @author : 孙超飞
 * @title :
 * @description :
 * @copyright :
 * @date : 2018-05-18 14:23
 */

public enum  CacheEnum {
    WX_SESSION_KEY("WX_SESSION_KEY",300L,"微信sessionkey");
    private String prefix;

    private Long expireTime;

    private String description;

    private static final String SPLITTER = "_";

    CacheEnum(String prefix, Long expireTime, String description) {
        this.prefix = prefix;
        this.expireTime = expireTime;
        this.description = description;
    }

    public String getCacheKey(Object... args) {
        StringBuilder keyBuilder = new StringBuilder().append(this.prefix);
        if (args != null && args.length > 0) {
            keyBuilder.append(SPLITTER);
            String joinedStr = Arrays.stream(args).map(arg -> arg == null ? "0" : arg.toString())
                    .collect(Collectors.joining(SPLITTER));
            keyBuilder.append(joinedStr);
        }
        return keyBuilder.toString();
    }

    public Long getExpireTime() {
        return expireTime;
    }
}
